package com.hivekion.common.socket;

import org.java_websocket.WebSocket;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class SocketServerUtils {

    private static Integer serverPort;  //直播评论服务端socket端口

    private static Integer videosServerPort; //视讯终端服务端socket端口

    //@Value("${socket.server.port}")
    public void setSocketServerPort(Integer port) {
        serverPort = port;
    }

    //@Value("${socket.videos.server.port}")
    public void setSocketVideosServerPort(Integer port) {
        videosServerPort = port;
    }

    public static Map<String, List<WebSocket>> listMap = new HashMap<>();

    public static Map<SocketReceiveVideosDataModel, WebSocket> videosListMap = new HashMap<>();

    public static void Init() {
        listMap.clear();

        try {
            MyWebSocketService webSocketServer = new MyWebSocketService(serverPort);
            webSocketServer.start();
        } catch (Exception ex) {

        }
    }

    public static void InitVideos() {
        videosListMap.clear();

        try {
            MyWebSocketVideosService socketVideosService = new MyWebSocketVideosService(videosServerPort);
            socketVideosService.start();
        } catch (Exception ex) {

        }
    }

}
